<?php
/**
 * Created by PhpStorm.
 * User: zhc
 * Date: 2018/10/29 0029
 * Time: 21:49
 */
namespace model;
class  PolicyModel extends \model\CommonModel{

    //保险人员保单状态
    const POLICY_REVISE_STATUS    = 0;//驳回修改
    const POLICY_NOT_LOOK_STATUS    = 1; //未提交审核
    const POLICY_RECORDOR_NOT_USED_STATUS    = 2;//代录人未提交审核
    const POLICY_ECORDO_NOT_CONFITM_STATUS    = 3;//代录人未确认
    const POLICY_CHECK_PENDING_STATUS    = 4;//待审核
    const POLICY_HOLDEL_NOT_CONFITM_STATUS    = 5;//被保险人未确认
    const POLICY_HOLDEL_NOT_ENTRUST_STATUS    = 6;//被保险人未委托
    const POLICY_COMPLETE_STATUS    = 7;//全部资料已完成
    const POLICY_AUCTION_COMPLETE_STATUS    = 8;//拍卖完成


    protected $table = 'policy';

    /**
     * 查询单条保单全部信息
     * @param $policy_id
     * @return \think\Collection|\think\model\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getPolicyInfo($policy_id)
    {
        $join = [
            ['policy_item','policy_item.policy_num=policy.policy_num','LEFT'],
            ['user_info','user_info.ui_id=policy.ui_id','LEFT'],
        ];
        $field = 'policy.report_num,policy.insurance_type,policy_item.*,user_info.username,user_info.mobile,user_info.company_name';
        $info = $this->join($join)->where('policy.policy_num',$policy_id)->field($field)->find();
        return $info;
    }

    /**
     * 获取所有被保险人信息
     * @return \think\Collection|\think\model\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getInsurantInfo()
    {
        $join = [
            ['insurant i','i.p_id=policy.p_id','LEFT'],
        ];
        $field = 'policy.p_id,policy.report_num,i.created_at,i.status';
        $info = $this->join($join)->where('i.delete_ts',0)->field($field)->order('i.status asc')->select();
        return collection($info);
    }




}